package com.zbbt.sportslottery.util;

import android.view.View;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.zbbt.sportslottery.app.App;

public class ViewUtil {
	static int heightDiffTemp = 0;

	/**
	 * 
	 * @MethodName:listenerSoftInput
	 * @Description: 监听软键盘
	 * @author：LiZhimin
	 * @date：2014-12-18 下午10:07:46
	 * @param mRootView
	 * @param mScrollView
	 *            void
	 */
	public static void listenerSoftInput(final LinearLayout imageView, final View mRootView) {

		mRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

			@Override
			public void onGlobalLayout() {
				int mParentHeight = mRootView.getRootView().getHeight();
				int mRootHeight = mRootView.getHeight();
				int heightDiff = mParentHeight - mRootHeight;
				LogUtil.printI("ViewUtil", "rootHeight:" + mParentHeight + "  mviewHeight:" + mRootHeight);
				if (Math.abs(heightDiff - heightDiffTemp) > 300) {
					if (heightDiff >= 300) {
						LogUtil.printI("ViewUtil", "FOCUS_DOWN");
						imageView.setVisibility(View.GONE);
						// mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
					} else {
						LogUtil.printI("ViewUtil", "FOCUS_UP");
						imageView.setVisibility(View.VISIBLE);
						// mScrollView.fullScroll(ScrollView.FOCUS_UP);
					}
					heightDiffTemp = heightDiff;
				}
			}
		});
	}

	/**
	 * 
	 * @MethodName:getDialogWidth
	 * @Description: 计算弹窗宽度
	 * @author：LiZhimin
	 * @date：2014-12-26 下午12:45:22
	 * @return int
	 */
	public static int getDialogWidth() {
		int widthDp = (int) (App.SCREEN_WIDTH / App.SCREEN_DENSITY);
		int padding = 60;
		if (widthDp < 340) {
			padding = 40;
		} else if (widthDp >= 380) {
			padding = 100;
		}
		return (int) ((widthDp - padding) * App.SCREEN_DENSITY);
	}
}
